package com.bff.gaia.mix.api.xjoin2.core.utils;

import com.alibaba.fastjson.JSONObject;
import com.bff.gaia.types.Row;

import java.util.List;

public class KeyUtil {
	public static String buildKey(JSONObject val, List<String> equalFieldList) {
		StringBuilder sb = new StringBuilder("");
		for (String equalField : equalFieldList) {
			sb.append(val.get(equalField)).append("_");
		}

		return sb.toString();
	}

	public static String buildKey(JSONObject val, String... equalFieldList) {
		StringBuilder sb = new StringBuilder("");
		for (String equalField : equalFieldList) {
			sb.append(val.get(equalField)).append("_");
		}

		return sb.toString();
	}

	public static String buildKey(Row val, List<Integer> equalFieldList) {
		StringBuilder sb = new StringBuilder("");
		for (int equalField : equalFieldList) {
			sb.append(val.getField(equalField)).append("_");
		}

		return sb.toString();
	}

	public static String buildKey(Row val, int... equalFieldList) {
		StringBuilder sb = new StringBuilder("");
		for (int equalField : equalFieldList) {
			sb.append(val.getField(equalField)).append("_");
		}

		return sb.toString();
	}
}